﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Services_WarehouseManage : ATPages
{
    ZSql zs = new ZSql();
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            initGvData();
            hfxs.Value = Request.QueryString["moduid"].ToString();
            lblPath.Text = f.getModuleidAdd(Request["moduid"]);
            hfuserId.Value = Request.Cookies["user"].Values["id"].ToString();

            //this.GvData.Columns[0].Visible = false;

        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("WarehouseAdd.aspx?moduid=" + Request["moduid"] + "&action=add");
    }

    private void initGvData()
    {
        string sql = "select  *, convert(char(10),editDate,120) as eidtdat,warebh from SV_Warehouse";
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;

    }

    protected void btnFlag_Click(object sender, EventArgs e)
    {
        int n = 0;
        if (this.GvData.Rows.Count > 0)
        {
            for (int i = 0; i < GvData.Rows.Count; i++)
            {
                CheckBox ck = GvData.Rows[i].Cells[10].FindControl("ckFlag") as CheckBox;
                if (ck.Checked)
                {
                    zs.Open("update  SV_Warehouse set AuditState='已通过' where WarehouseId=" + this.GvData.Rows[i].Cells[0].Text);
                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('审核成功');", true);
                }
                else
                {
                    n++;
                }

                if (n == this.GvData.Rows.Count)
                {
                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('至少应选择一项')", true);
                }
            }
        }

    }
    protected void lnkbtnEdit_Click(object sender, EventArgs e)
    {
        string id = (sender as LinkButton).CommandArgument;
        Response.Redirect("WarehouseAdd.aspx?id=" + id + "&action=update&moduid=" + Request["moduid"]);
    }
    protected void lnkbtnFlag_Click(object sender, EventArgs e)
    {
        string id = (sender as LinkButton).CommandArgument;
        Response.Redirect("WarehouseAdd.aspx?id=" + id + "&action=flag&moduid=" + Request["moduid"]);
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        int n = 0;
        if (this.GvData.Rows.Count > 0)
        {
            for (int i = 0; i < GvData.Rows.Count; i++)
            {
                CheckBox ck = GvData.Rows[i].Cells[11].FindControl("ckFlag") as CheckBox;
                if (ck.Checked)
                {
                    zs.Open("delete SV_Warehouse  where WarehouseId=" + this.GvData.Rows[i].Cells[0].Text);
                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('删除成功');", true);
                }
                else
                {
                    n++;
                }
                if (n == this.GvData.Rows.Count)
                {

                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('至少应选择一项')", true);
                }
            }
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string sql = "select  *, convert(char(10),editDate,120) as eidtdat,warebh from SV_Warehouse where 1=1";
        if (txtContent.Text != "")
        {
            sql += " and  WarehouseName like'%" + Common.FormatParameter(txtContent.Text) + "%'";
        }
        if (txtadres.Text != "")
        {
            sql += " and warebh like'%" + Common.FormatParameter(txtadres.Text) + "%'";
        }
        if (txtuser.Text != "")
        {
            sql += " and WarehouseMan like'%" + Common.FormatParameter(txtuser.Text) + "%'";
        }

        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }
    protected void GvData_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        f.checkLevels(Request.Cookies["user"].Values["roleid"], Request["moduid"], 10, GvData, btnDel, btnFlag, btnAdd);
    }
}
